package PTA.ch06;

import java.util.*;
import java.util.Map.Entry;

public class ex13 {
    public static String formate(String s) {
        String str = "";

        for( int i = 0; i < s.length(); i ++  ) {
            if( s.charAt(i) == '!' || s.charAt(i) == '.' ||  s.charAt(i) == ',' || s.charAt(i) == ':' ||  s.charAt(i) == '*' || s.charAt(i) == '?') {
                continue;
            }
            else {
                str += s.charAt(i);
            }
        }

        return str.toLowerCase(); // 转化为小写
    }

    public static void main(String []args)
    {
        Scanner cin = new Scanner(System.in);
        TreeMap<String, Integer> tm = new TreeMap<>();

        while( true ) {
            String s = cin.nextLine();
            if( s.equals("!!!!!")) {
                break;
            }
            if( s != null && s.equals("")) {
                continue;
            }
            String []ss = s.split(" ");
            for( int i = 0; i < ss.length;  i++ ) {
                String str = formate(ss[i]);
                if( str == null || str.length() == 0){ // 特殊情况只有符号
                    continue;
                }
                if( tm.containsKey(str)) {
                    tm.put(str, tm.get(str) + 1);
                }
                else {
                    tm.put(str, 1);
                }
            }
        }

        // 排序
        List<Map.Entry<String, Integer>> list = new ArrayList<>(tm.entrySet());
        Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {

            @Override
            public int compare(Entry<String, Integer> arg0, Entry<String, Integer> arg1) {
                // TODO Auto-generated method stub
                if(arg0.getValue()-arg1.getValue()!=0)
                    return arg1.getValue()-(arg0.getValue());
                else
                    return arg0.getKey().compareTo(arg1.getKey());
            }
        });

        System.out.println(tm.size());
        int cnt = 0;
        for( Map.Entry<String, Integer> entry : list) {
            System.out.println(entry.getKey() + "=" + entry.getValue());
            cnt ++;
            if( cnt == 10 ) {
                break;
            }
        }
        cin.close();
    }
}

